import config from './config.js';
import httpApi from './api.js'
export default {
	//转译
	html_decode(str){ 
		    var s = ""; 
		    //console.log(str)
		    if (str.length == 0) return ""; 
		    s = str.replace(/&amp;/g, "&"); 
		    s = s.replace(/&lt;/g, "<"); 
		    s = s.replace(/&gt;/g, ">"); 
		    s = s.replace(/&nbsp;/g, " "); 
		    s = s.replace(/&#39;/g, "\'"); 
		    s = s.replace(/&quot;/g, "\""); 
		    s = s.replace(/<br\/>/g, "\n"); 
		    return s; 
		},
	// 生成随机数
	GenNonDuplicateID(randomLength){
	 return Number(Math.random().toString().substr(3,randomLength) + Date.now()).toString(36)
	},
	// 通过时间戳  返回到 秒
	handleAllTime (a) {
	    let b = new Date(a * 1000)
	    var y = b.getFullYear()
	    var mon = b.getMonth() + 1
	    var day = b.getDate()
	    var h = b.getHours()
	    h = h < 10 ? '0' + h : h
	    var m = b.getMinutes()
	    m = m < 10 ? '0' + m : m
	    var s = b.getSeconds()
	    s = s < 10 ? '0' + s : s
	    // return y + '年' + mon + '月' + day + '日' + h + ':' + m + ':' + s
	   return y + '-' + mon + '-' + day
	},
	handleAllTimeHm (a) {
	    let b = new Date(a * 1000)
	    var y = b.getFullYear()
	    var mon = b.getMonth() + 1
	    var day = b.getDate()
	    var h = b.getHours()
	    h = h < 10 ? '0' + h : h
	    var m = b.getMinutes()
	    m = m < 10 ? '0' + m : m
	    var s = b.getSeconds()
	    s = s < 10 ? '0' + s : s
	    // return y + '年' + mon + '月' + day + '日' + h + ':' + m + ':' + s
	   // return y + '-' + mon + '-' + day
	   return y + '-' + mon + '-' + day +' ' + h + ':' + m 
	},
	handleAllTimeHmDay (a) {
	    let b = new Date(a)
	    var y = b.getFullYear()
	    var mon = b.getMonth() + 1
	    var day = b.getDate()
	    var h = b.getHours()
	    h = h < 10 ? '0' + h : h
	    var m = b.getMinutes()
	    m = m < 10 ? '0' + m : m
	    var s = b.getSeconds()
	    s = s < 10 ? '0' + s : s
	    // return y + '年' + mon + '月' + day + '日' + h + ':' + m + ':' + s
	   // return y + '-' + mon + '-' + day
	   return y + '年' + mon + '月'
	},
	// 是否是微信浏览器
	isWxBrowser() {
	  let ua = navigator.userAgent.toLowerCase()
	  let isWxBrowser = ua.indexOf('micromessenger') !== -1
	  console.log('isWxBrowser : ' + isWxBrowser)
	  return isWxBrowser
	},
	//是否为苹果设备
	isIphone() {
	  let userAgent = navigator.userAgent
	  let isIphone = userAgent.includes('iPhone') || userAgent.includes('iPad')
	  console.log('isIphone : ' + isIphone)
	  return isIphone
	},
	// 是否为App
	isApp() {
	  let u = navigator.userAgent
	  let isApp = u.indexOf('bocapp(') > -1
	  console.log('isApp : ' + isApp)
	  return isApp
	},
	// 公共跳转方法
	jump(url, type = 1) {
		// 保留当前页面，跳转到应用内的某个页面
		if (type == 1) {
			uni.navigateTo({
				url: url
			})
		}

		// 关闭当前页面，跳转到应用内的某个页面
		if (type == 2) {
			uni.redirectTo({
				url: url
			})
		}
		// 关闭所有页面，打开到应用内的某个页面
		if (type == 3) {
			uni.reLaunch({
				url: url
			})
		}

		// 跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面
		if (type == 4) {
			uni.switchTab({
				url: url
			})
		}
	},
	tostring(value){
		return JSON.stringify(value);
	},
   getUrlQuery () {
     var url = location.search
     console.log(url,'截取url 中的code')
     var theRequest = {}
     if (url.indexOf('?') != -1) {
       var str = url.substr(1)
       var strs = str.split('&')
       for (var i = 0; i < strs.length; i++) {
         theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
       }
     }
     return theRequest
   },
   delCodeandstate () { // 函数作用：去除url中的code和state
     console.log('去除url中的code和state')
     var url = window.location.href // 获取当前页面的url
     if (url.indexOf('?') != -1) { // 判断是否存在参数
       url = url.replace(/(\?|#)[^'"]*/, '') // 去除参数
       window.history.pushState({}, 0, url)
     }
   },
   authUser (code) {
		//微信登录
		
	 return false
   },
   
	newDateFormat(originVal) {
     
     const dt = new Date(parseInt(originVal))
     const y = dt.getFullYear()
     const m = (dt.getMonth() + 1 + '').padStart(2, '0')
     const d = (dt.getDate() + '').padStart(2, '0')
     const hh = (dt.getHours() + '').padStart(2, '0')
     const mm = (dt.getMinutes() + '').padStart(2, '0')
     const ss = (dt.getSeconds() + '').padStart(2, '0')
     return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
	 }
   
}
